package com.ruoyi.web.controller.warning;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.warning.domain.entity.Property;
import com.ruoyi.warning.domain.query.DisposeQuery;
import com.ruoyi.warning.domain.query.PropertyQuery;
import com.ruoyi.warning.domain.vo.DisposeVO;
import com.ruoyi.warning.mapper.DisposeMapper;
import com.ruoyi.warning.mapper.PropertyMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenhc
 * @since 2025-07-15
 */
@RestController
@RequestMapping("/statistics")
@Api(tags = "查询统计", description = "用于查询统计相关操作的控制器")
public class StatisticsController {

    @Resource
    private DisposeMapper disposeMapper;
    @Resource
    private PropertyMapper propertyMapper;

    @ApiOperation("服务器统计")
    @GetMapping(value = "/serviceStatistics")
    public R serviceStatistics(PropertyQuery query)
    {
        return R.ok();
    }

    @ApiOperation("处理统计")
    @GetMapping(value = "/disposeStatistics")
    public R disposeStatistics(DisposeQuery query)
    {
        System.out.println( query);
        Page<Property> page = PageHelper.startPage(query.getPageNum(),query.getPageSize());
        List<DisposeVO> list = disposeMapper.disposeStatistics(query);
        return R.ok(new TableDataInfo(list, page.getTotal()));
    }

    @ApiOperation("工厂统计")
    @PostMapping(value = "/areaStatistics")
    public R areaStatistics(@RequestBody List<String> list)
    {
//        Page<Property> page = PageHelper.startPage(query.getPageNum(),query.getPageSize());
        List<Map<String,String>> mapList = propertyMapper.areaStatistics();
        System.out.println(mapList);
        if(ObjectUtils.isNotEmpty(list)) {
            mapList = mapList.stream()
                    .filter(map -> list.contains(map.get("area")))
                    .collect(Collectors.toList());
        }
//        return R.ok(new TableDataInfo(list, page.getTotal()));
        return R.ok(mapList);
    }
}
